package com.zeei.ems.base.security.service;

import com.zeei.ems.base.dao.UserDao;
import com.zeei.ems.base.vo.UserVO;
import com.zeei.ems.meet.dao.MeetingContactDao;
import com.zeei.ems.meet.model.MeetingContactVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AuthService {

    @Autowired
    UserDao userDao;
    @Autowired
    MeetingContactDao meetingContactDao;

    public UserVO login(String loginName, String password){

        UserVO basUser = userDao.getUserByLoginName(loginName);
        if(basUser!=null){
            if (basUser.getLoginpw().equals(password)){
                MeetingContactVO meetingContact = meetingContactDao.getMeetingContact(basUser.getUserid());
                if (meetingContact != null){
                    basUser.setContactUserId(meetingContact.getUserId());
                }

                return basUser;
            }
        }

        return null;
    }

    public UserVO getUserByUsername(String loginName){
        UserVO basUser = userDao.getUserByLoginName(loginName);
        if(basUser!=null){
            MeetingContactVO meetingContact = meetingContactDao.getMeetingContact(basUser.getUserid());
            if (meetingContact != null){
                basUser.setContactUserId(meetingContact.getUserId());
            }
        }
        return basUser;
    }

}
